//
//  DMMemberVC.m
//  DistributionMallApp
//
//  Created by JHnoplan on 2018/10/19.
//  Copyright © 2018年 JHnoplan. All rights reserved.
//

#import "DMMemberVC.h"
#import "DMMemberFirstCell.h"
#import "DMMemberSecondCell.h"
#import "DMMemberThirdCell.h"

@interface DMMemberVC ()<UITableViewDelegate,UITableViewDataSource>
{
    NSInteger flag;//1会员
}
@property (weak, nonatomic) IBOutlet UITableView *tableView;


@end

@implementation DMMemberVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self startInit];
}

-(void)startInit {
    
    self.navigationItem.title = @"会员权益";
    
    //TODO:-假数据
    flag = 0;
    
    _tableView.delegate = self;
    _tableView.dataSource = self;
    //注册cell
    [self.tableView registerNib:[UINib nibWithNibName:@"DMMemberFirstCell" bundle:nil] forCellReuseIdentifier:@"DMMemberFirstCell"];
    [self.tableView registerNib:[UINib nibWithNibName:@"DMMemberSecondCell" bundle:nil] forCellReuseIdentifier:@"DMMemberSecondCell"];
    [self.tableView registerNib:[UINib nibWithNibName:@"DMMemberThirdCell" bundle:nil] forCellReuseIdentifier:@"DMMemberThirdCell"];
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 2;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (section == 1) {
        return 5;
    }
    return 1;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    if (section == 1) {
        return 63;
    }
    return 0.01;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    if (section == 1) {
        UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 63)];
        view.backgroundColor = DMWhiteColor;
        
        UIView *line = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 11)];
        line.backgroundColor = DMDefaultColor;
        [view addSubview:line];
        
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 21, ScreenWidth, 22)];
        label.text = @"—VIP会员权益—";
        label.textColor = DMFontColor;
        label.font = DMFontSize(16);
        label.textAlignment = NSTextAlignmentCenter;
        [view addSubview:label];
        
        return view;
    }
    return nil;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 0.01;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        if (flag == 1) {
            return 148;
        }
        return 228;
    }
    self.tableView.rowHeight = UITableViewAutomaticDimension;
    self.tableView.estimatedRowHeight = 100;
    return self.tableView.rowHeight;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        if (flag == 1) {
            DMMemberSecondCell *cell = [tableView dequeueReusableCellWithIdentifier:@"DMMemberSecondCell" forIndexPath:indexPath];
            if (cell == nil) {
                cell = [[NSBundle mainBundle]loadNibNamed:@"DMMemberSecondCell" owner:self options:nil].firstObject;
            }
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            
            return cell;
        }
        DMMemberFirstCell *cell = [tableView dequeueReusableCellWithIdentifier:@"DMMemberFirstCell" forIndexPath:indexPath];
        if (cell == nil) {
            cell = [[NSBundle mainBundle]loadNibNamed:@"DMMemberFirstCell" owner:self options:nil].firstObject;
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        [cell setClickButton:^{
            self.tabBarController.selectedIndex = 0;
            [self.navigationController popToRootViewControllerAnimated:YES];
        }];
        return cell;
    }
    DMMemberThirdCell *cell = [tableView dequeueReusableCellWithIdentifier:@"DMMemberThirdCell" forIndexPath:indexPath];
    if (cell == nil) {
        cell = [[NSBundle mainBundle]loadNibNamed:@"DMMemberThirdCell" owner:self options:nil].firstObject;
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;

    NSArray *arr = @[@"新人：顾客在PC、移动端完成注册或在苏宁门店办理会员卡即可成为新人会员；",
                     @"新人升V1:新注册会员完成单件商品实际付款金额大于10元以上的订单即可升级V1（实际支付金额不包括券、云钻、运费在内）；",
                     @"V1-V4会员：按照最近1年内产生的成长值及购物天数，满足条件即可实时升级。 注：新人和V1不再降级",
                     @"升级：会员达到升级所需的成长值和购买天数，系统即会自动升级；",
                     @"降级：当会员最近1年内产生的成长值和购物天数不再满足当前等级的条件，系统将会自动降级；"];
    cell.contentLb.text = arr[indexPath.row];
    return cell;
}





@end
